;;; s7 library tests

(set! (hook-functions *unbound-variable-hook*) ())

(if (not (provided? 'cload.scm)) (load "cload.scm"))

;;; --------------------------------------------------------------------------------

(define (ok? otst ola oexp)
  (let ((result (catch #t ola
		       (lambda args
			 (if (not (eq? oexp 'error)) 
			     (begin (display args) (newline)))
			 'error))))
    (if (not (equal? result oexp))
	(format #t "~A: ~A got ~S but expected ~S~%~%" (port-line-number) otst result oexp))))

(define-macro (test tst expected) ;(display tst) (newline)
  `(ok? ',tst (lambda () ,tst) ,expected))

(define (op-error op result expected)
  
  (define (conjugate n) 
    (make-rectangular (real-part n) (- (imag-part n))))
  
  (if (and (real? result)
	   (real? expected))
      (/ (abs (- result expected)) (max 1.0 (abs expected)))
      (case op
	((acosh)
	 (/ (magnitude (- (cosh result) (cosh expected)))
	    (max 0.001 (magnitude (cosh expected)))))
	((asin)
	 (/ (min (magnitude (- (sin result) (sin expected)))
		 (magnitude (- result expected)))
	    (max 0.001 (* 10 (magnitude (sin expected))))))
	((acos)
	 (/ (min (magnitude (- (cos result) (cos expected)))
		 (magnitude (- result expected)))
	    (max 0.001 (magnitude (cos expected)))))
	((asinh)
	 (/ (magnitude (- (sinh result) (sinh expected)))
	    (max 0.001 (magnitude (sinh expected)))))
	((atanh)
	 (/ (min (magnitude (- (tanh result) (tanh expected)))
		 (magnitude (- result expected)))
	    (max 0.001 (magnitude (tanh expected)))))
	((atan)
	 (/ (min (magnitude (- (tan result) (tan expected)))
		 (magnitude (- result expected)))
	    (max 0.001 (magnitude (tan expected)))))
	((cosh)
	 (/ (min (magnitude (- result expected))
		 (magnitude (- result (- expected))))
	    (max 0.001 (magnitude expected))))
	(else (/ (magnitude (- result expected)) (max 0.001 (magnitude expected)))))))


;;; relative error (/ (abs (- x res) (abs x)))

(define error-12 1e-12)
(define error-6  1e-6)

(define (number-ok? tst result expected)
  (if (not (eq? result expected))
      (if (or (and (not (number? expected))
		   (not (eq? result expected)))
	      (and (nan? expected)
		   (not (nan? result)))
	      (and (nan? result)
		   (not (nan? expected)))
	      (and (number? expected)
		   (or (not (number? result))
		       (nan? result)))
	      (and (rational? expected)
		   (rational? result)
		   (not (= result expected)))
	      (and (or (rational? expected) 
		       (rational? result))
		   (real? expected)
		   (real? result)
		   (> (/ (abs (- result expected)) (max 1.0 (abs expected))) error-12))
	      (and (pair? tst)
		   (> (op-error (car tst) result expected) error-6)))

	  (begin
	    (format #t "~A: ~A got ~A~Abut expected ~A~%" 
		    (port-line-number) tst result 
		    (if (and (rational? result) (not (rational? expected)))
			(format #f " (~A) " (* 1.0 result))
			" ")
		    expected)
	    
	    (if (and (not (number? expected))
		     (not (eq? result expected)))
		(format #t "    (eq? ~A ~A) -> #f" result expected)
		(if (and (number? expected)
			 (or (not (number? result))
			     (nan? result)))
		    (begin
		      (if (not (number? result))
			  (format #t "    (number? ~A) but not (number? ~A)" expected result)
			  (format #t "    (number? ~A) but (nan? ~A)" expected result)))
		    (if (and (rational? expected)
			     (rational? result)
			     (not (= result expected)))
			(format #t "    exact results but not (= ~A ~A): ~A" expected result (= result expected))
			(if (and (or (rational? expected) 
				     (rational? result))
				 (real? expected)
				 (real? result)
				 (> (abs (- result expected)) error-12))
			    (format #t "    rational results but diff > ~A: ~A" error-12 (abs (- result expected)))
			    (if (and (pair? tst)
				     (< (op-error (car tst) result expected) error-6))
				(let ((n result))
				  (format #t "    result not internally consistent")
				  (if (and (integer? n) 
					   (or (not (= (denominator n) 1))
					       (not (= n (numerator n)))
					       (not (zero? (imag-part n)))
					       (not (= (floor n) (ceiling n) (truncate n) (round n) n))
					       (not (= n (real-part n)))))
				      (format #t "    ~A integer but den: ~A, num: ~A, imag: ~A, real: ~A, floors: ~A ~A ~A ~A"
					      n (denominator n) (numerator n) (imag-part n) (real-part n)
					      (floor n) (ceiling n) (truncate n) (round n))
				      (if (and (rational? n)
					       (not (integer? n))
					       (or (not (zero? (imag-part n)))
						   (= (denominator n) 1)
						   (= (denominator n) 0)
						   (not (= n (real-part n)))
						   (not (= n (/ (numerator n) (denominator n))))))
					  (format #t "    ~A ratio but imag: ~A, den: ~A, real: ~A, ~A/~A=~A"
						  n (imag-part n) (denominator n) (real-part n) 
						  (numerator n) (denominator n) (* 1.0 (/ (numerator n) (denominator n))))
					  (if (and (real? n)
						   (not (rational? n))
						   (or (not (zero? (imag-part n)))
						       (not (= n (real-part n)))))
					      (format #t "    ~A real but rational: ~A, imag: ~A, real: ~A"
						      n (rational? n) (imag-part n) (real-part n))
					      (format #t "    ~A complex but real? ~A, imag: ~A, ~A+~A=~A"
						      n (real? n) (imag-part n) (real-part n) (imag-part n)
						      (+ (real-part n) (* 0+i (imag-part n)))))))))))))
	    (newline) (newline)))))

(define (nok? otst ola oexp)
  (let ((result (catch #t ola 
		       (lambda args 
			 (format *stderr* "error: ~A~%" args)
			 'error))))
     (number-ok? otst result oexp)))

(define-macro (num-test tst expected) ;(display tst) (newline)
  `(nok? ',tst  (lambda () ,tst) ,expected))



;;; --------------------------------------------------------------------------------
;;; libm

(if (not (provided? 'libm.scm)) (load "libm.scm"))

(with-environment *libm*

  (define nan.0 (string->number "nan.0"))
  (define -nan.0 (- (string->number "nan.0")))
  (define inf.0 (string->number "+inf.0"))
  (define -inf.0 (- (string->number "+inf.0")))

  ;; __DBL_DENORM_MIN__ comes from gcc
  ;; these tests come from the autotester (I also tried those in glibc 2-17 math/libm-test.inc)  

  ;; just representative values -- maybe catch more possibilities?
  (num-test __DBL_DENORM_MIN__ 4.9406564584125e-324)
  (num-test __DBL_MAX__ 1.7976931348623e+308)
  (num-test __DBL_MIN__ 2.2250738585072e-308)
  (num-test __DBL_EPSILON__ 2.2204460492503e-16)
  (num-test __DBL_MIN_10_EXP__ -307)
  (num-test __DBL_MAX_10_EXP__ 308)
  (num-test __DBL_DIG__ 15)
  (num-test __DBL_MANT_DIG__ 53)
  (num-test __DBL_MIN_EXP__ -1021)
  (num-test __DBL_MAX_EXP__ 1024)
  (num-test __SIZEOF_DOUBLE__ 8)
  (num-test __SIZEOF_LONG_LONG__ 8)
  (num-test __LONG_LONG_MAX__ 9223372036854775807)

  (num-test FP_NAN 0)
  (num-test FP_INFINITE 1)
  (num-test FP_ZERO 2)
  (num-test FP_SUBNORMAL 3)
  (num-test FP_NORMAL 4)

  (num-test M_E (exp 1.0))
  (num-test M_LOG2E (/ (log 2)))
  (num-test M_LOG10E (/ (log 10)))
  (num-test M_LN2 (log 2))
  (num-test M_LN10 (log 10))
  (num-test M_PI pi)
  (num-test M_PI_2 (/ pi 2))
  (num-test M_PI_4 (/ pi 4))
  (num-test M_1_PI (/ pi))
  (num-test M_2_PI (/ 2 pi))
  (num-test M_2_SQRTPI (/ 2 (sqrt pi)))
  (num-test M_SQRT2 (sqrt 2))
  (num-test M_SQRT1_2 (/ (sqrt 2)))

  (num-test (j0 -1) 0.76519768655797)
  (num-test (j0 0) 1.0)
  (num-test (j0 1) 0.76519768655797)
  (num-test (j0 1.5) 0.51182767173592)
  (num-test (j0 -1234567.5) -0.00056797538542782)
  (num-test (j0 32.75) 0.11922756341796)
  (num-test (j0 3) -0.26005195490193)
  (num-test (j0 inf.0) 0.0)
  (test (nan? (j0 nan.0)) #t)

  (num-test (j1 -42) 0.045993888221887)
  (num-test (j1 -1) -0.44005058574493)
  (num-test (j1 0) 0.0)
  (num-test (j1 3/4) 0.34924360217486)
  (num-test (j1 -63) 0.057696680293944)
  (num-test (j1 inf.0) 0.0)
  (test (nan? (j1 nan.0)) #t)
  (num-test (j1 32.75) 0.074086803054576)
  (num-test (j1 1.5) 0.5579365079101)

  (test (nan? (erf nan.0)) #t)
  (num-test (erf -1) -0.84270079294971)
  (num-test (erf 0) 0.0)
  (num-test (erf 1.5) 0.96610514647531)
  (num-test (erf 3/4) 0.71115563365352)
  (num-test (erf -63) -1.0)
  (num-test (erf 3.1415926535898) 0.99999112385363)
  (num-test (erf inf.0) 1.0)

  (num-test (erfc inf.0) 0.0)
  (test (nan? (erfc nan.0)) #t)
  (num-test (erfc 1234567.6) 0.0)
  (num-test (erfc 1.5) 0.033894853524689)
  (num-test (erfc -1.5) 1.9661051464753)
  (num-test (erfc 3.0) 2.2090496998585e-05)

  (num-test (lgamma inf.0) inf.0)
  (test (nan? (lgamma nan.0)) #t)
  (num-test (lgamma 1.5) -0.12078223763525)
  (num-test (lgamma 3/4) 0.2032809514313)
  (num-test (lgamma 32.75) 80.688603510529)
  (num-test (lgamma 1.5) -0.12078223763525)
  (num-test (lgamma -1.5) 0.86004701537648)

  (num-test (fabs -1) 1.0)
  (num-test (fabs 0) 0.0)
  (num-test (fabs inf.0) inf.0)
  (test (nan? (fabs nan.0)) #t)
  (num-test (fabs 1234567.6) 1234567.6)
  (num-test (fabs -1234567.6) 1234567.6)
  (num-test (fabs -1.5) 1.5)

  (num-test (ceil -1) -1.0)
  (num-test (ceil 0) 0.0)
  (num-test (ceil inf.0) inf.0)
  (test (nan? (ceil nan.0)) #t)
  (num-test (ceil 1234567.6) 1234568.0)
  (num-test (ceil -1234567.6) -1234567.0)
  (num-test (ceil 1234567.5) 1234568.0)
  (num-test (ceil -1234567.5) -1234567.0)
  (num-test (ceil 32.75) 33.0)

  (num-test (nearbyint 1.5) 2.0)
  (num-test (nearbyint 3/4) 1.0)
  (num-test (nearbyint -63) -63.0)
  (num-test (nearbyint inf.0) inf.0)
  (test (nan? (nearbyint nan.0)) #t)
  (num-test (nearbyint 1234567.6) 1234568.0)
  (num-test (nearbyint 1234567.5) 1234568.0)
  (num-test (nearbyint -1234567.5) -1234568.0)
  (num-test (nearbyint 1/9223372036854775807) 0.0)

  (num-test (rint inf.0) inf.0)
  (test (nan? (rint nan.0)) #t)
  (num-test (rint 1234567.6) 1234568.0)
  (num-test (rint -1234567.6) -1234568.0)
  (num-test (rint 1234567.5) 1234568.0)
  (num-test (rint -1234567.5) -1234568.0)
  (num-test (rint 32.75) 33.0)
  (num-test (rint 1.5) 2.0)

  (num-test (llrint 3.1415926535898) 3)
  (num-test (llrint 1.5707963267949) 2)
  (num-test (llrint 1234567.6) 1234568)
  (num-test (llrint -1234567.6) -1234568)
  (num-test (llrint 1234567.5) 1234568)
  (num-test (llrint -1234567.5) -1234568)
  (num-test (llrint 32.75) 33)

  (num-test (llround 1.5) 2)
  (num-test (llround 3/4) 1)
  (num-test (llround 1234567.6) 1234568)
  (num-test (llround -1234567.6) -1234568)
  (num-test (llround 1234567.5) 1234568)
  (num-test (llround -1234567.5) -1234568)
  (num-test (llround 32.75) 33)

  (num-test (trunc 1.5707963267949) 1.0)
  (num-test (trunc inf.0) inf.0)
  (test (nan? (trunc nan.0)) #t)
  (num-test (trunc 1234567.6) 1234567.0)
  (num-test (trunc -1234567.6) -1234567.0)
  (num-test (trunc 1234567.5) 1234567.0)
  (num-test (trunc -1234567.5) -1234567.0)
  (num-test (trunc 32.75) 32.0)
  (num-test (trunc 1.5) 1.0)
  (num-test (trunc -1.5) -1.0)

  (test (nan? (fmod nan.0 -42.0)) #t)
  (num-test (fmod 3.1415926535898 3) 0.14159265358979)
  (num-test (fmod 32.75 -1.5) 1.25)
  (num-test (fmod 32.75 1.5) 1.25)

  (num-test (ldexp -1 6) -64.0)
  (num-test (ldexp 0 6) 0.0)
  (num-test (ldexp 6 6) 384.0)
  (num-test (ldexp 3.0 1) 6.0)
  (num-test (ldexp 6 0) 6.0)
  (num-test (ldexp inf.0 -1) inf.0)
  (test (nan? (ldexp nan.0 -1)) #t)

  (num-test (scalbn 1.5 3) 12.0)
  (num-test (scalbn 3.0 6) 192.0)
  (num-test (scalbn 1.5 1) 3.0)
  (num-test (scalbn 6 -1) 3.0)

  (num-test (scalbln inf.0 -42) inf.0)
  (test (nan? (scalbln nan.0 -42)) #t)
  (num-test (scalbln 3.0 3) 24.0)
  (num-test (scalbln 0 -42) 0.0)
  (num-test (scalbln -1.5 6) -96.0)
  (num-test (scalbln 3.0 6) 192.0)
  (num-test (scalbln 1 -1) 0.5)
  (num-test (scalbln 1.5 -1) 0.75)

  (num-test (exp2 -1) 0.5)
  (num-test (exp2 0) 1.0)
  (num-test (exp2 1.5) 2.8284271247462)
  (num-test (exp2 3/4) 1.6817928305074)
  (num-test (exp2 6) 64.0)
  (num-test (exp2 inf.0) inf.0)
  (test (nan? (exp2 nan.0)) #t)

  (num-test (expm1 inf.0) inf.0)
  (test (nan? (expm1 nan.0)) #t)
  (num-test (expm1 -1) -0.63212055882856)
  (num-test (expm1 0) 0.0)
  (num-test (expm1 1) 1.718281828459)
  (num-test (expm1 1.5) 3.4816890703381)
  (num-test (expm1 3/4) 1.1170000166127)
  (num-test (expm1 -63) -1.0)

  (num-test (log10 inf.0) inf.0)
  (test (nan? (log10 nan.0)) #t)
  (num-test (log10 32.75) 1.5152113043278)
  (num-test (log10 1.5) 0.17609125905568)
  (num-test (log10 1) 0.0)
  (num-test (log10 1234567.6) 6.0915148751535)

  (num-test (log1p inf.0) inf.0)
  (test (nan? (log1p nan.0)) #t)
  (num-test (log1p 1234567.6) 14.02623215528)
  (num-test (log1p 0.0) 0.0)
  (num-test (log1p 1) 0.69314718055995)
  (num-test (log1p 1.5) 0.91629073187416)
  (num-test (log1p 3/4) 0.55961578793542)

  (num-test (log2 inf.0) inf.0)
  (test (nan? (log2 nan.0)) #t)
  (num-test (log2 1234567.6) 20.235574404197)
  (num-test (log2 1) 0.0)
  (num-test (log2 32.75) 5.0334230015375)
  (num-test (log2 1.5) 0.58496250072116)

  (num-test (ilogb 3.1415926535898) 1)
  (num-test (ilogb 1.5707963267949) 0)
  (num-test (ilogb inf.0) 2147483647)
  (num-test (ilogb nan.0) -2147483648)
  (num-test (ilogb 1234567.6) 20)
  (num-test (ilogb -1234567.6) 20)
  (num-test (ilogb 1) 0)
  (num-test (ilogb 3.0) 1)

  (num-test (cbrt inf.0) inf.0)
  (test (nan? (cbrt nan.0)) #t)
  (num-test (cbrt 1234567.6) 107.27658956435)
  (num-test (cbrt -1) -1.0)
  (num-test (cbrt 0) 0.0)
  (num-test (cbrt 1) 1.0)
  (num-test (cbrt 1.5) 1.1447142425533)
  (num-test (cbrt 3.0) 1.4422495703074)

  (num-test (hypot 0 -42.0) 42.0)
  (num-test (hypot 1 3) 3.1622776601684)
  (num-test (hypot 1.5 3) 3.3541019662497)
  (num-test (hypot 3/4 3) 3.0923292192132)
  (num-test (hypot inf.0 -1.5) inf.0)
  (test (nan? (hypot nan.0 -1.5)) #t)
  (num-test (hypot 1.5 32.75) 32.784333148625)

  (num-test (fma 3.0 3 -42.0) -33.0)
  (num-test (fma 6 -42 -42.0) -294.0)
  (num-test (fma 1.5 -42 -42.0) -105.0)
  (num-test (fma -1.5 -42 -42.0) 21.0)
  (num-test (fma 3.0 -42 -42.0) -168.0)
  (num-test (fma inf.0 1.5 -42.0) inf.0)

  (test (nan? (pow nan.0 -42.0)) #t)
  (num-test (pow 1 3) 1.0)
  (num-test (pow 1.5 3) 3.375)
  (num-test (pow 3/4 3) 0.421875)
  (num-test (pow -63 3) -250047.0)
  (num-test (pow 6 3) 216.0)
  (num-test (pow 0.0 3.0) 0.0)

  (num-test (fdim 1.5 -42) 43.5)
  (num-test (fdim -1.5 -42) 40.5)
  (num-test (fdim 3.0 -42) 45.0)
  (num-test (fdim 0 -42.0) 42.0)
  (test (nan? (fdim 0.0 nan.0)) #t)
  (num-test (fdim 1 6) 0.0)
  (num-test (fdim 32.75 6) 26.75)

  (num-test (tgamma 1.5) 0.88622692545276)
  (num-test (tgamma 3/4) 1.2254167024652)
  (num-test (tgamma 3.1415926535898) 2.28803779534)
  (num-test (tgamma 1.5707963267949) 0.89056089038154)
  (num-test (tgamma inf.0) inf.0)
  (test (nan? (tgamma nan.0)) #t)
  (num-test (tgamma -1.5) 2.3632718012074)
  (num-test (tgamma 3.0) 2.0)

  (num-test (copysign -1.5 3) 1.5)
  (num-test (copysign 3/4 -42.0) -0.75)
  (num-test (copysign inf.0 3.0) inf.0)
  (test (nan? (copysign nan.0 3.0)) #t)
  (num-test (copysign 1.5 3.0) 1.5)
  (num-test (copysign -1.5 3.0) 1.5)

  (num-test (nextafter 1 -42) 1.0)
  (num-test (nextafter 1.5 -42) 1.5)
  (num-test (nextafter 3/4 -42) 0.75)
  (test (nan? (nextafter nan.0 -1.5)) #t)
  (num-test (nextafter 0 -1.5) -4.9406564584125e-324)

  (num-test (nexttoward 0 -42) -4.9406564584125e-324)
  (num-test (nexttoward 1.5 3) 1.5)

  (num-test (isfinite inf.0) 0)
  (num-test (isfinite nan.0) 0)
  (num-test (isfinite 1234567.6) 1)
  (num-test (isfinite -1234567.6) 1)
  (num-test (isfinite 9223372036854775807) 1)

  (num-test (isinf inf.0) 1)
  (num-test (isinf nan.0) 0)
  (num-test (isinf 1234567.6) 0)
  (num-test (isinf -9223372036854775807) 0)
  (num-test (isinf -1) 0)
  (num-test (isinf 0) 0)

  (num-test (isnan inf.0) 0)
  (num-test (isnan nan.0) 1)
  (num-test (isnan 1234567.6) 0)

  (num-test (isnormal inf.0) 0)
  (num-test (isnormal nan.0) 0)
  (num-test (isnormal 1234567.6) 1)
  (num-test (isnormal 0) 0)

  (num-test (signbit 1.5) 0)
  (num-test (signbit -1.5) 128)
  (num-test (signbit -1) 128)
  (num-test (signbit 0) 0)
  (num-test (signbit inf.0) 0)
  (num-test (signbit nan.0) 0)

  (num-test (floor 1.5) 1.0)
  (num-test (floor 3/4) 0.0)
  (num-test (floor -63) -63.0)
  (num-test (floor inf.0) inf.0)
  (test (nan? (floor nan.0)) #t)
  (num-test (floor 1234567.6) 1234567.0)
  (num-test (floor -1234567.6) -1234568.0)
  (num-test (floor 1234567.5) 1234567.0)
  (num-test (floor -1234567.5) -1234568.0)
  (num-test (floor 32.75) 32.0)
  (num-test (floor 1.5) 1.0)
  (num-test (floor -1.5) -2.0)

  (num-test (round inf.0) inf.0)
  (test (nan? (round nan.0)) #t)
  (num-test (round 1234567.6) 1234568.0)
  (num-test (round -1234567.6) -1234568.0)
  (num-test (round 1234567.5) 1234568.0)
  (num-test (round -1234567.5) -1234568.0)
  (num-test (round 32.75) 33.0)
  (num-test (round 1.5) 2.0)
  (num-test (round -1.5) -2.0)

  (test (nan? (remainder nan.0 -42)) #t)
  (num-test (remainder 1234567.6 -42) 19.600000000093)
  (num-test (remainder -63 3.0) 0.0)
  (num-test (remainder 32.75 3.0) -0.25)
  (test (nan? (remainder 3.0 nan.0)) #t)
  (num-test (remainder -1.5 3/4) 0.0)

  (num-test (exp 1.5707963267949) 4.8104773809654)
  (num-test (exp inf.0) inf.0)
  (test (nan? (exp nan.0)) #t)
  (num-test (exp -1) 0.36787944117144)
  (num-test (exp 0) 1.0)
  (num-test (exp 1.5) 4.4816890703381)
  (num-test (exp 3/4) 2.1170000166127)

  (num-test (log 6) 1.7917594692281)
  (num-test (log 3.1415926535898) 1.1447298858494)
  (num-test (log 1.5707963267949) 0.45158270528945)
  (num-test (log inf.0) inf.0)
  (test (nan? (log nan.0)) #t)
  (num-test (log 1234567.6) 14.02623134528)
  (num-test (log 32.75) 3.4889029620813)
  (num-test (log 1.5) 0.40546510810816)

  (num-test (sqrt 0.0) 0.0)
  (num-test (sqrt 1) 1.0)
  (num-test (sqrt 1.5) 1.2247448713916)
  (num-test (sqrt 3/4) 0.86602540378444)
  (num-test (sqrt 6) 2.4494897427832)
  (num-test (sqrt 3.1415926535898) 1.7724538509055)
  (num-test (sqrt 1.5707963267949) 1.2533141373155)
  (num-test (sqrt inf.0) inf.0)
  (test (nan? (sqrt nan.0)) #t)
  (num-test (sqrt 1234567.6) 1111.1109755555)

  (num-test (cos 0.0) 1.0)
  (num-test (cos 1) 0.54030230586814)
  (num-test (cos 1.5) 0.070737201667703)
  (num-test (cos 3/4) 0.73168886887382)
  (num-test (cos -63) 0.98589658158255)
  (num-test (cos 6) 0.96017028665037)
  (num-test (cos 3.1415926535898) -1.0)
  (num-test (cos 1.5707963267949) 6.1232339957368e-17)
  (test (nan? (cos nan.0)) #t)
  (num-test (cos 1234567.6) -0.97435594756269)

  (num-test (sin 0.0) 0.0)
  (num-test (sin 1) 0.8414709848079)
  (num-test (sin 1.5) 0.99749498660405)
  (num-test (sin 3/4) 0.68163876002333)
  (num-test (sin -63) -0.16735570030281)
  (num-test (sin 6) -0.27941549819893)
  (num-test (sin 3.1415926535898) 1.2246467991474e-16)
  (num-test (sin 1.5707963267949) 1.0)
  (test (nan? (sin nan.0)) #t)
  (num-test (sin 1234567.6) -0.22501219400117)

  (num-test (tan 0.0) 0.0)
  (num-test (tan 1) 1.5574077246549)
  (num-test (tan 1.5) 14.101419947172)
  (num-test (tan 3/4) 0.93159645994407)
  (num-test (tan -63) -0.16974975208269)
  (num-test (tan 6) -0.29100619138475)
  (num-test (tan 3.1415926535898) -1.2246467991474e-16)
  (test (nan? (tan nan.0)) #t)
  (num-test (tan 1234567.6) 0.23093428491305)

  (num-test (sinh 0.0) 0.0)
  (num-test (sinh 1) 1.1752011936438)
  (num-test (sinh 1.5) 2.1292794550948)
  (num-test (sinh 3/4) 0.82231673193583)
  (num-test (sinh -63) -1.1468915797348e+27)
  (num-test (sinh 6) 201.71315737028)
  (num-test (sinh 3.1415926535898) 11.548739357258)
  (num-test (sinh 1.5707963267949) 2.3012989023073)
  (num-test (sinh inf.0) inf.0)
  (test (nan? (sinh nan.0)) #t)
  (num-test (sinh 1234567.6) inf.0)

  (num-test (tanh 0.0) 0.0)
  (num-test (tanh 1) 0.76159415595576)
  (num-test (tanh 1.5) 0.90514825364487)
  (num-test (tanh 3/4) 0.63514895238729)
  (num-test (tanh -63) -1.0)
  (num-test (tanh 6) 0.9999877116508)
  (num-test (tanh 3.1415926535898) 0.99627207622075)
  (num-test (tanh 1.5707963267949) 0.91715233566727)
  (num-test (tanh inf.0) 1.0)
  (test (nan? (tanh nan.0)) #t)
  (num-test (tanh 1234567.6) 1.0)

  (num-test (acos 1) 0.0)
  (num-test (acos 3/4) 0.72273424781342)
  (test (nan? (acos 1.5707963267949)) #t)
  (num-test (acos -1) 3.1415926535898)
  (num-test (acos 0) 1.5707963267949)

  (num-test (asin 0.0) 0.0)
  (num-test (asin 1) 1.5707963267949)
  (test (nan? (asin inf.0)) #t)
  (test (nan? (asin nan.0)) #t)
  (num-test (asin 3/4) 0.84806207898148)

  (num-test (atan 0.0) 0.0)
  (num-test (atan 1) 0.78539816339745)
  (num-test (atan 1.5) 0.98279372324733)
  (num-test (atan 3/4) 0.64350110879328)
  (num-test (atan -63) -1.5549246438031)
  (num-test (atan 6) 1.4056476493803)
  (num-test (atan 3.1415926535898) 1.2626272556789)
  (num-test (atan 1.5707963267949) 1.0038848218539)
  (num-test (atan inf.0) 1.5707963267949)
  (test (nan? (atan nan.0)) #t)
  (num-test (atan 1234567.6) 1.5707955167947)

  (test (nan? (atan2 nan.0 3.0)) #t)
  (num-test (atan2 -1 3) -0.32175055439664)
  (num-test (atan2 -1 32.75) -0.030524866917203)
  (num-test (atan2 0.0 3) 0.0)
  (num-test (atan2 1 3) 0.32175055439664)
  (num-test (atan2 1.5 3) 0.46364760900081)
  (num-test (atan2 3/4 3) 0.24497866312686)
  (num-test (atan2 -63 3) -1.5232132235179)

  (num-test (acosh 1) 0.0)
  (num-test (acosh 1.5) 0.96242365011921)
  (num-test (acosh 6) 2.4778887302885)
  (num-test (acosh 3.1415926535898) 1.8115262724609)
  (num-test (acosh 1.5707963267949) 1.0232274785476)
  (num-test (acosh inf.0) inf.0)
  (test (nan? (acosh nan.0)) #t)
  (num-test (acosh 1234567.6) 14.71937852584)

  (num-test (asinh 0.0) 0.0)
  (num-test (asinh 1) 0.88137358701954)
  (num-test (asinh 1.5) 1.1947632172871)
  (num-test (asinh 3/4) 0.69314718055995)
  (num-test (asinh -63) -4.8363448891593)
  (num-test (asinh 6) 2.4917798526449)
  (num-test (asinh 3.1415926535898) 1.8622957433108)
  (num-test (asinh 1.5707963267949) 1.2334031175112)
  (num-test (asinh inf.0) inf.0)
  (test (nan? (asinh nan.0)) #t)
  (num-test (asinh 1234567.6) 14.71937852584)

  (num-test (atanh 0.0) 0.0)
  (num-test (atanh 3/4) 0.97295507452766)
  (test (nan? (atanh nan.0)) #t)

  (morally-equal? (remquo -42.0 -42.0) '(0.0 1))
  (morally-equal? (remquo 1234567.5 3) '(1.5 2))
  (morally-equal? (remquo 3.1415926535898 3) '(0.14159265358979 1))
  (morally-equal? (remquo -63 3.0) '(0.0 -5))
  (morally-equal? (remquo 1 -1.5) '(-0.5 -1))
  (morally-equal? (remquo 3/4 1.5) '(0.75 0))

  (morally-equal? (frexp 0.0) '(0.0 0))
  (morally-equal? (frexp 1) '(0.5 1))
  (morally-equal? (frexp 1.5) '(0.75 1))
  (morally-equal? (frexp 3/4) '(0.75 0))
  (morally-equal? (frexp -63) '(-0.984375 6))
  (morally-equal? (frexp 6) '(0.75 3))
  (morally-equal? (frexp 3.1415926535898) '(0.78539816339745 2))
  (morally-equal? (frexp 1.5707963267949) '(0.78539816339745 1))
  (morally-equal? (frexp inf.0) '(inf.0 0))
  (morally-equal? (frexp nan.0) '(nan.0 0))
  (morally-equal? (frexp 1234567.6) '(0.58868770599365 21))

  (morally-equal? (modf 0.0) '(0.0 0.0))
  (morally-equal? (modf 1) '(0.0 1.0))
  (morally-equal? (modf 1.5) '(0.5 1.0))
  (morally-equal? (modf 3/4) '(0.75 0.0))
  (morally-equal? (modf -63) '(0.0 -63.0))
  (morally-equal? (modf 6) '(0.0 6.0))
  (morally-equal? (modf 3.1415926535898) '(0.14159265358979 3.0))
  (morally-equal? (modf 1.5707963267949) '(0.5707963267949 1.0))
  (morally-equal? (modf inf.0) '(0.0 inf.0))
  (morally-equal? (modf nan.0) '(nan.0 nan.0))
  (morally-equal? (modf 1234567.6) '(0.60000000009313 1234567.0))
  )

;;; --------------------------------------------------------------------------------
